package com.example.kotlin;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.aserbao.aserbaosandroid.functions.database.greenDao.db.DaoMaster;
import com.aserbao.aserbaosandroid.functions.database.greenDao.db.StudentDao;

import org.greenrobot.greendao.database.Database;

import java.util.concurrent.Executors;


public class MyOpenHelper extends DaoMaster.OpenHelper {
    public MyOpenHelper(Context context, String name) {
        super(context, name);
    }

    public MyOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(final Database db, int oldVersion, int newVersion) {
        Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
//        // TODO:  注意把所新版本的表的xxDao都添加到这里
        Executors.defaultThreadFactory().newThread(() -> MigrationHelper.getInstance().migrate(db, StudentDao.class)).start();
    }
}
